namespace WebRtcProject.Models.Configuration
{
    /// <summary>
    /// Consul 服务发现和配置管理选项
    /// 用于微服务架构中的服务注册、发现和健康检查
    /// </summary>
    public class ConsulOptions
    {
        public const string SectionName = "Consul";

        /// <summary>
        /// 基础连接配置
        /// </summary>
        public string Host { get; set; } = "localhost";
        public int Port { get; set; } = 8500;
        public string Scheme { get; set; } = "http";
        public bool Enabled { get; set; } = true;
        public string? Token { get; set; }
        public string? Datacenter { get; set; }

        /// <summary>
        /// 服务注册配置
        /// </summary>
        public ServiceRegistrationOptions ServiceRegistration { get; set; } = new();

        /// <summary>
        /// 健康检查配置
        /// </summary>
        public HealthCheckOptions HealthCheck { get; set; } = new();

        /// <summary>
        /// 服务发现配置
        /// </summary>
        public ServiceDiscoveryOptions ServiceDiscovery { get; set; } = new();

        /// <summary>
        /// 配置管理选项
        /// </summary>
        public ConfigurationOptions Configuration { get; set; } = new();

        /// <summary>
        /// 连接和重试配置
        /// </summary>
        public ConnectionOptions Connection { get; set; } = new();
    }

    /// <summary>
    /// 服务注册配置
    /// </summary>
    public class ServiceRegistrationOptions
    {
        public string ServiceName { get; set; } = "webrtc-signaling-server";
        public string ServiceId { get; set; } = "";  // 自动生成
        public string ServiceHost { get; set; } = "localhost";
        public int ServicePort { get; set; } = 5001;
        public string[] Tags { get; set; } //= { "webrtc", "signaling", "realtime" };
        public Dictionary<string, string> Meta { get; set; } = new();
        public bool AutoRegister { get; set; } = true;
        public bool AutoDeregister { get; set; } = true;
    }

    /// <summary>
    /// 健康检查配置
    /// </summary>
    public class HealthCheckOptions
    {
        public bool Enabled { get; set; } = true;
        public string CheckUrl { get; set; } = "/health";
        public TimeSpan Interval { get; set; } = TimeSpan.FromSeconds(30);
        public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(10);
        public TimeSpan DeregisterAfter { get; set; } = TimeSpan.FromMinutes(5);
        public string CheckMethod { get; set; } = "GET";
        public Dictionary<string, string> Headers { get; set; } = new();
    }

    /// <summary>
    /// 服务发现配置
    /// </summary>
    public class ServiceDiscoveryOptions
    {
        public bool Enabled { get; set; } = true;
        public TimeSpan CacheTimeout { get; set; } = TimeSpan.FromMinutes(5);
        public bool OnlyHealthyServices { get; set; } = true;
        public string[] WatchedServices { get; set; } = { "rabbitmq", "redis", "database" };
        public TimeSpan RefreshInterval { get; set; } = TimeSpan.FromSeconds(30);
    }

    /// <summary>
    /// 配置管理选项
    /// </summary>
    public class ConfigurationOptions
    {
        public bool Enabled { get; set; } = true;
        public string KeyPrefix { get; set; } = "webrtc/config";
        public bool WatchChanges { get; set; } = true;
        public TimeSpan PollInterval { get; set; } = TimeSpan.FromSeconds(30);
        public string[] WatchedKeys { get; set; } = 
        { 
            "webrtc/config/rabbitmq",
            "webrtc/config/signaling",
            "webrtc/config/performance"
        };
    }

    /// <summary>
    /// 连接和重试配置
    /// </summary>
    public class ConnectionOptions
    {
        public TimeSpan ConnectTimeout { get; set; } = TimeSpan.FromSeconds(10);
        public int MaxRetryAttempts { get; set; } = 3;
        public TimeSpan RetryDelay { get; set; } = TimeSpan.FromSeconds(5);
        public bool ExponentialBackoff { get; set; } = true;
        public TimeSpan MaxRetryDelay { get; set; } = TimeSpan.FromMinutes(1);
    }
} 